package com.dries.security.app.social;

import cn.hutool.core.util.StrUtil;
import com.dries.security.core.properties.SecurityCoreConstants;
import com.dries.security.core.social.config.DriesSpringSocialConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @Author ZSY
 * @createTime 2020/9/20 15:50
 */
@Slf4j
@Component
public class AppSocialConfigurerPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

        if (StrUtil.equals(beanName, "driesSocialConfigurer")) {
            DriesSpringSocialConfig config = (DriesSpringSocialConfig) bean;
            config.signupUrl(SecurityCoreConstants.DEFAULT_SOCIAL_USER_INFO_URL);
            return config;
        }
        return bean;
    }

}
